package reflect;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Scanner;

public class ReflectDemo1 {
    public static void main(String[] args) throws ClassNotFoundException {
        /*

         */
        //获取String的类对象
//        Class cls = String.class;
//        Class cls = ArrayList.class;


//        Class cls = Class.forName("java.lang.String");
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个类名:");
        String classname = scan.nextLine();
        Class cls = Class.forName(classname);

        String name = cls.getName();
        System.out.println(name);
        //仅获取类名
        name = cls.getSimpleName();
        System.out.println(name);
        //获取包信息
        Package p = cls.getPackage();//获取String的包信息
        System.out.println(p.getName());//获取包名

        Method[] methods = cls.getMethods();
        System.out.println(name+"类共有"+methods.length+"个公开方法");
        for (Method m:methods){
            System.out.println(m.getName());
        }
    }
}
